home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_19_1987_Transactor_Publishing.d64
/
sorting demo
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2023-02-26
|
542b
|
23 lines
10 input"how many names";n
20 dim a(n),b(n),a$(n),t$(n)
30 for j=1 to n: print: print"number";j
40 input"surname";s$
50 input"first name";f$
60 t$(j)=s$+", "+f$: rem combine surnames with last names
70 input"age";a$(j)
80 a(j)=j: h=j+1
90 h=h-1: if t$(j)<t$(a(h-1))then a(h)=a(h-1): goto 90: rem sort names
100 a(h)=j
110 b(j)=j: h=j+1
120 h=h-1: if a$(j)<a$(b(h-1))then b(h)=b(h-1): goto 120: rem sort ages
130 b(h)=j
140 next j
150 print: print"sorted alphabetically"
160 for j=1 to n
170 print t$(a(j)), a$(a(j))
180 next j
190 print:print" sorted by age:"
200 for j=1 to n
210 print t$(b(j)), a$(b(j))
220 next j